<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of TinySong
 *
 * @author techi
 */
class TinySong
{

    /**
     * Informace o hledane skladeb z tinysong db
     *
     * @see http://www.tinysong.com/api
     * @param string $name
     * @return array
     */
    public static function request($name, $mode = "b")
    {
        $app_key = GlobalConfig::getInstance()->getConfig()->tinysong->app_key;

        $name = str_replace('+', ' ', $name);
        $name = str_replace('/', '', $name);
        $name = urlencode($name);

        $client = new Zend_Http_Client();
        $client->setUri("http://tinysong.com/$mode/$name");
        $client->setParameterGet('format', 'json');
        $client->setParameterGet('key', $app_key);

        $response = $client->request();

        $result = $response->getBody();

        return Zend_Json::decode($result);
    }

    /**
     * Vrati seznam skladeb s podobnym nazvem
     *
     * @param string $name
     * @return array JSON objekt
     */

    public static function search($name)
    {
        return self::request($name, "s");
    }

}